//
//  UIView+DataBind.m
//  DataBind
//
//  Created by Super on 2019/12/18.
//  Copyright © 2019 Super. All rights reserved.
//

#import "UIView+DataBind.h"

#define DataBindViewProps @[@"backgroundColor"]

@implementation UIView (DataBind)

- (void)bindKey:(NSString *)key observer:(id)observer {
    [self addObserver:observer forKeyPath:key options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
}

- (void)unbindKey:(NSString *)key observer:(id)observer {
    [self removeObserver:observer forKeyPath:key];
}

- (void)updateChange:(NSString *)uiBindProp value:(id)value {
    NSUInteger index = [DataBindViewProps indexOfObject:uiBindProp];
    switch (index) {
        case 0:
            [self updateBackgroundColor:value];
            break;
            
        default:
            break;
    }
}

- (void)updateBackgroundColor:(id)value {
    UIColor *color = (UIColor *)value;
    self.backgroundColor = color;
}

@end
